//
//  MineViewController.m
//  必争医疗
//
//  Created by 毕成 on 14-11-19.
//  Copyright (c) 2014年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "MineViewController.h"
#import "ChunYuModel.h"
#import "ChunYuModel1.h"
#import "RegistrateViewController.h"
#import "QuestionViewController.h"
#import "TelphoneViewController.h"
#import "ToolViewController.h"
#import "MemberViewController.h"
#import "NurceViewController.h"
#import "AsyncGetModel.h"
@interface MineViewController ()

@end

@implementation MineViewController

- (void)dealloc
{

    [_firstmodel release];
    [_secondmodel release];
    [super dealloc];
}

- (instancetype)init
{
    self = [super init];
    if (self) {

        self.firstmodel = [[[ChunYuModel alloc] init] autorelease];
        self.secondmodel = [[[ChunYuModel1 alloc] init] autorelease];
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self.view setBackgroundColor:[UIColor whiteColor]];
    
    self.navigationController.navigationBar.translucent = NO;
    [self.navigationItem setTitle:@"我的春雨"];
    
    [AsyncGetModel asyncWithUrl:MyChunyuUrl dic:nil block:^(NSMutableData *data) {
        NSMutableArray *arr = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
        NSMutableDictionary *first = [arr firstObject];
        NSMutableDictionary *second = [arr lastObject];
        [self.firstmodel setValuesForKeysWithDictionary:first];
        [self.secondmodel setValuesForKeysWithDictionary:second];
        
        [self creatScroll];
    }];

}

- (void)viewWillAppear:(BOOL)animated
{
    //防止返回时隐藏tabbar
    [self.tabBarController.tabBar setHidden:NO];
}

- (void)creatScroll
{
    UIScrollView *mine = [[[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 113)] autorelease];
    [mine setBackgroundColor:[UIColor blueColor]];
    [mine setContentSize:CGSizeMake(0, 1.01 * mine.frame.size.height)];
    mine.alwaysBounceVertical = YES;
    [self.view addSubview:mine];
    //第一行，四个按钮
    UIView *buttonView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, mine.frame.size.width, mine.frame.size.height / 4)] autorelease];
    [buttonView setBackgroundColor:[UIColor whiteColor]];
    buttonView.layer.borderWidth = 0.5;
    [mine addSubview:buttonView];
    //提问按钮
    UIImageView *askImage = [[[UIImageView alloc] initWithFrame:CGRectMake(25, 20, 60, 50)] autorelease];
    [askImage setImage:[UIImage imageNamed:@"免费提问.png"]];
    [buttonView addSubview:askImage];
    UILabel *askLabel = [[[UILabel alloc] initWithFrame:CGRectMake(askImage.frame.origin.x, askImage.frame.origin.y + askImage.frame.size.height, 60, 30)] autorelease];
    [askLabel setBackgroundColor:[UIColor whiteColor]];
    [askLabel setText:@"免费提问"];
    askLabel.textAlignment = NSTextAlignmentCenter;
    askLabel.font = [UIFont fontWithName:nil size:12];
    [buttonView addSubview:askLabel];
    UIButton *askButton = [[[UIButton alloc] initWithFrame:CGRectMake(askImage.frame.origin.x, 7, 60, 80)] autorelease];
    [askButton setBackgroundColor:[UIColor clearColor]];
    [askButton addTarget:self action:@selector(questionAction:) forControlEvents:UIControlEventTouchUpInside];
    [buttonView addSubview:askButton];
    //电话按钮
    UIImageView *TelImage = [[[UIImageView alloc] initWithFrame:CGRectMake(askImage.frame.origin.x + askImage.frame.size.width + 25, 20, 60, 50)] autorelease];
    [TelImage setImage:[UIImage imageNamed:@"快捷电话.png"]];
    [buttonView addSubview:TelImage];
    UILabel *TelLabel = [[[UILabel alloc] initWithFrame:CGRectMake(TelImage.frame.origin.x, TelImage.frame.origin.y + TelImage.frame.size.height, 60, 30)] autorelease];
    [TelLabel setBackgroundColor:[UIColor whiteColor]];
    [TelLabel setText:@"快捷电话"];
    TelLabel.textAlignment = NSTextAlignmentCenter;
    TelLabel.font = [UIFont fontWithName:nil size:12];
    [buttonView addSubview:TelLabel];
    UIButton *TelButton = [[[UIButton alloc] initWithFrame:CGRectMake(TelImage.frame.origin.x, 7, 60, 80)] autorelease];
    [TelButton setBackgroundColor:[UIColor clearColor]];
    [TelButton addTarget:self action:@selector(phoneAction:) forControlEvents:UIControlEventTouchUpInside];
    [buttonView addSubview:TelButton];
    //工具按钮
    UIImageView *toolImage = [[[UIImageView alloc] initWithFrame:CGRectMake(TelImage.frame.origin.x + TelImage.frame.size.width + 25, 20, 60, 50)] autorelease];
    [toolImage setImage:[UIImage imageNamed:@"健康工具.png"]];
    [buttonView addSubview:toolImage];
    UILabel *toolLabel = [[[UILabel alloc] initWithFrame:CGRectMake(toolImage.frame.origin.x, toolImage.frame.origin.y + toolImage.frame.size.height, 60, 30)] autorelease];
    [toolLabel setBackgroundColor:[UIColor whiteColor]];
    [toolLabel setText:@"健康工具"];
    toolLabel.textAlignment = NSTextAlignmentCenter;
    toolLabel.font = [UIFont fontWithName:nil size:12];
    [buttonView addSubview:toolLabel];
    UIButton *toolButton = [[[UIButton alloc] initWithFrame:CGRectMake(toolImage.frame.origin.x, 10, 60, 80)] autorelease];
    [toolButton setBackgroundColor:[UIColor clearColor]];
    [toolButton addTarget:self action:@selector(toolAction:) forControlEvents:UIControlEventTouchUpInside];
    [buttonView addSubview:toolButton];
    //升级按钮
    UIImageView *memberImage = [[[UIImageView alloc] initWithFrame:CGRectMake(toolImage.frame.origin.x + toolImage.frame.size.width + 25, 20, 60, 50)] autorelease];
    [memberImage setImage:[UIImage imageNamed:@"会员升级.png"]];
    [buttonView addSubview:memberImage];
    UILabel *memberLabel = [[[UILabel alloc] initWithFrame:CGRectMake(memberImage.frame.origin.x, memberImage.frame.origin.y + memberImage.frame.size.height, 60, 30)] autorelease];
    [memberLabel setBackgroundColor:[UIColor whiteColor]];
    [memberLabel setText:@"会员升级"];
    memberLabel.textAlignment = NSTextAlignmentCenter;
    memberLabel.font = [UIFont fontWithName:nil size:12];
    [buttonView addSubview:memberLabel];
    UIButton *memberButton = [[[UIButton alloc] initWithFrame:CGRectMake(memberImage.frame.origin.x, 10, 60, 80)] autorelease];
    [memberButton setBackgroundColor:[UIColor clearColor]];
    [memberButton addTarget:self action:@selector(memberAction:) forControlEvents:UIControlEventTouchUpInside];
    [buttonView addSubview:memberButton];
    
    //第二行：提问历史
    UIView *questionView = [[[UIView alloc] initWithFrame:CGRectMake(buttonView.frame.origin.x, buttonView.frame.origin.y + buttonView.frame.size.height, buttonView.frame.size.width, buttonView.frame.size.height)] autorelease];
    questionView.layer.borderWidth = 0.5;
    [questionView setBackgroundColor:[UIColor whiteColor]];
    [mine addSubview:questionView];
    UIImageView *questionImage = [[[UIImageView alloc] initWithFrame:CGRectMake(15, 15, 80, 80)] autorelease];
    [questionImage setImage:[UIImage imageNamed:@"提问历史"]];
    [questionView addSubview:questionImage];
    UILabel *questionLabel = [[[UILabel alloc] initWithFrame:CGRectMake(questionImage.frame.origin.x + questionImage.frame.size.width + 15, questionImage.frame.origin.y, 265, 40)] autorelease];
    [questionLabel setText: self.firstmodel.name];
    //[questionLabel setText:@"我的提问历史"];
    [questionView addSubview:questionLabel];
    UILabel *questionlabel = [[[UILabel alloc] initWithFrame:CGRectMake(questionLabel.frame.origin.x, questionLabel.frame.origin.y + questionLabel.frame.size.height, questionLabel.frame.size.width, 40)] autorelease];
    [questionlabel setText:self.firstmodel.msg];
    //[questionlabel setText:@"查看我的图文、电话提问历史"];
    questionlabel.font = [UIFont fontWithName:nil size:15];
    [questionView addSubview:questionlabel];
    UIButton *questionButton = [[[UIButton alloc] initWithFrame:CGRectMake(questionView.frame.origin.x, questionView.frame.origin.y, questionView.frame.size.width, questionView.frame.size.height)] autorelease];
    [questionButton setBackgroundColor:[UIColor clearColor]];
    questionButton.layer.borderWidth = 0.5;
    [questionButton addTarget:self action:@selector(registrateAction:) forControlEvents:UIControlEventTouchUpInside];
    [mine addSubview:questionButton];

    //第三行：跑步
    UIView *runView = [[[UIView alloc] initWithFrame:CGRectMake(questionView.frame.origin.x, questionView.frame.origin.y + questionView.frame.size.height, questionView.frame.size.width, questionView.frame.size.height)] autorelease];
    runView.layer.borderWidth = 0.5;
    [runView setBackgroundColor:[UIColor whiteColor]];
    [mine addSubview:runView];
    UIImageView *runImage = [[[UIImageView alloc] initWithFrame:CGRectMake(15, 15, 80, 80)] autorelease];
    [runImage setImage:[UIImage imageNamed:@"跑步"]];
    [runView addSubview:runImage];
    UILabel *runLabel = [[[UILabel alloc] initWithFrame:CGRectMake(runImage.frame.origin.x + runImage.frame.size.width + 15, runImage.frame.origin.y, 265, 40)] autorelease];
    [runLabel setText:@"每天5000步"];
    [runView addSubview:runLabel];
    UILabel *runlabel = [[[UILabel alloc] initWithFrame:CGRectMake(runLabel.frame.origin.x, runLabel.frame.origin.y + runLabel.frame.size.height, runLabel.frame.size.width, 40)] autorelease];
    [runlabel setText:@"查看今天步行数、消耗热量"];
    runlabel.font = [UIFont fontWithName:nil size:15];
    [runView addSubview:runlabel];
    UIButton *runButton = [[[UIButton alloc] initWithFrame:CGRectMake(runView.frame.origin.x, runView.frame.origin.y, questionView.frame.size.width, runView.frame.size.height)] autorelease];
    [runButton setBackgroundColor:[UIColor clearColor]];
    [runButton addTarget:self action:@selector(runAction:) forControlEvents:UIControlEventTouchUpInside];
    [mine addSubview:runButton];
    
    //第四行：护士
    UIView *nurseView = [[[UIView alloc] initWithFrame:CGRectMake(runView.frame.origin.x, runView.frame.origin.y + runView.frame.size.height, runView.frame.size.width, runView.frame.size.height)] autorelease];
    [nurseView setBackgroundColor:[UIColor whiteColor]];
    [mine addSubview:nurseView];
    UIImageView *nurseImage = [[[UIImageView alloc] initWithFrame:CGRectMake(15, 15, 80, 80)] autorelease];
    [nurseImage setImage:[UIImage imageNamed:@"护士"]];
    [nurseView addSubview:nurseImage];
    UILabel *nurseLabel = [[[UILabel alloc] initWithFrame:CGRectMake(nurseImage.frame.origin.x + nurseImage.frame.size.width + 15, nurseImage.frame.origin.y, 265, 40)] autorelease];
    [nurseLabel setText:self.secondmodel.name];
    [nurseView addSubview:nurseLabel];
    UILabel *nurselabel = [[[UILabel alloc] initWithFrame:CGRectMake(nurseLabel.frame.origin.x, nurseLabel.frame.origin.y + nurseLabel.frame.size.height, nurseLabel.frame.size.width, 40)] autorelease];
    [nurselabel setText:self.secondmodel.msg];
    [nurseView addSubview:nurselabel];
    UIButton *nurseButton = [[[UIButton alloc] initWithFrame:CGRectMake(nurseView.frame.origin.x, nurseView.frame.origin.y, nurseView.frame.size.width, nurseView.frame.size.height)] autorelease];
    [nurseButton setBackgroundColor:[UIColor clearColor]];
    [nurseButton addTarget:self action:@selector(nurceAction:) forControlEvents:UIControlEventTouchUpInside];
    [mine addSubview:nurseButton];
    
    UILabel *NewUserLabel = [[[UILabel alloc] initWithFrame:CGRectMake(5, mine.frame.size.height, 335, 30)] autorelease];
    [NewUserLabel setBackgroundColor:[UIColor orangeColor]];
    [NewUserLabel setText:@"欢迎使用春雨医生，新用户注册赢金币"];
    [self.view addSubview:NewUserLabel];
    UIImageView *NewUserImage = [[[UIImageView alloc] initWithFrame:CGRectMake(NewUserLabel.frame.origin.x + NewUserLabel.frame.size.width, NewUserLabel.frame.origin.y, 30, 30)] autorelease];
    [NewUserImage setBackgroundColor:[UIColor orangeColor]];
    [NewUserImage setImage:[UIImage imageNamed:@"right.png"]];
    [self.view addSubview:NewUserImage];
    UIButton *registrate = [[[UIButton alloc] initWithFrame:CGRectMake(NewUserLabel.frame.origin.x, NewUserLabel.frame.origin.y, NewUserLabel.frame.size.width + NewUserImage.frame.size.width, NewUserLabel.frame.size.height)] autorelease];
    [registrate setBackgroundColor:[UIColor clearColor]];
    [registrate addTarget:self action:@selector(registrateAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:registrate];
    
}

- (void)questionAction:(id)sender
{
    QuestionViewController *question = [[QuestionViewController alloc] init];
    [self.navigationController pushViewController:question animated:YES];
}

- (void)phoneAction:(id)sender
{
    TelphoneViewController *phone = [[TelphoneViewController alloc] init];
    [self.navigationController pushViewController:phone animated:YES];
}

- (void)toolAction:(id)sender
{
    ToolViewController *tool = [[ToolViewController alloc] init];
    [self.navigationController pushViewController:tool animated:YES];
}

- (void)memberAction:(id)sender
{
    MemberViewController *member = [[MemberViewController alloc] init];
    [self.navigationController pushViewController:member animated:YES];
}

- (void)registrateAction:(id)sender
{
    
    RegistrateViewController *registrate = [[RegistrateViewController alloc] init];
    [self.navigationController pushViewController:registrate animated:YES];
}

- (void)runAction:(id)sender
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"是否安装春雨计步器" message:nil delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"安装", nil];
    [alert show];
    [alert release];
}

- (void)nurceAction:(id)sender
{
    NurceViewController *nurce = [[NurceViewController alloc] init];
    [self.navigationController pushViewController:nurce animated:YES];
}







- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
